package com.uenpay.im.panel.emoji;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.qyx.android.weight.edittext.Emoji;
import com.uenpay.im.R;

/**
 * 
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * 
 */
public class EmojiGridAdapter extends BaseAdapter {
	private Emoji[] emojis;
	private LayoutInflater _inflater;

	public EmojiGridAdapter(Context context, Emoji[] emojiArray) {
		emojis = emojiArray;
		_inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return emojis.length;
	}

	@Override
	public Emoji getItem(int i) {
		return emojis[i];
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		ViewHolder holder;
		if (view == null) {
			holder = new ViewHolder();
			view = _inflater.inflate(R.layout.emoji_item_view, viewGroup,false);
			holder.imageView = (ImageView) view.findViewById(R.id.emoji_item);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}

		holder.imageView.setImageResource(emojis[i].resourceId);
		return view;
	}

	class ViewHolder {
		ImageView imageView;
	}
}
